package cn.newgrand.netcall.consultant;

import java.util.HashMap;
import java.util.Map;

import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.spark.SparkManager;

import cn.newgrand.smackx.consultant.ConsultantManager;

public class SpecialistQueueSizeManager {
	
	private Map<String, String> queueSizes = new HashMap<String, String>();
	
	private static SpecialistQueueSizeManager instance;
	
	private SpecialistQueueSizeManager(){
		
	}
	
	public synchronized static SpecialistQueueSizeManager getInstance(){
		if(instance == null){
			instance = new SpecialistQueueSizeManager();
		}
		return instance;
	}
	
	public void sendQueueSizePacket(){
		try {
			queueSizes = ConsultantManager.getInstance(SparkManager.getConnection()).getSpecialistQueueSizes();
		} catch (XMPPException e) {
			e.printStackTrace();
		}
	}
	
	public String getQueueSize(String spid){
		if(isHashSpid(spid)){
			return queueSizes.get(spid);
		}else{
			return "";
		}
	}
	
	public boolean isHashSpid(String spid){
		return queueSizes.containsKey(spid);
	}

}
